package org.example.serve;

import io.vertx.core.Vertx;

public class VertxHttpServer implements HttpServer{
    /**
     * 启动服务
     *
     * @param port
     */
    @Override
    public void start(int port) {
        //创建vertx实例
        Vertx vertx = Vertx.vertx();
        //创建http服务
        io.vertx.core.http.HttpServer httpServer = vertx.createHttpServer();
        //添加请求处理程序
//        httpServer.requestHandler(request -> {
//            System.out.println("接受到请求方法"+request.method());
//            //发送响应
//            request.response().putHeader("content-type", "text/plain")
//                    .end("Hello from Vert.x HTTP server!");
//        });
        httpServer.requestHandler(new HttpServerHandle());
        //启动服务
        httpServer.listen(port,result->{
            if(result.succeeded()){
                System.out.println("服务启动成功");
            }else{
                System.out.println("服务启动失败");
            }
        });

    }
}
